<?php

namespace app\common\model\record;

use think\Model;

class RecordLateLeaveEarly extends Model 
{ 
    protected $name = 'record_late_leave_early'; 

    protected $schema = [
        'id'             => 'int', //早退迟到记录表
        'uid'             => 'int', //用户ID
        'remark'             => 'varchar', //备注
        'create_time'             => 'datetime', //创建时间
        'examine_admin_name'             => 'varchar', //审核人
        'admin_name'             => 'varchar', //录入人
        'status'             => 'tinyint', //-2 拒绝 -1 删除 0 待审核 1正常
        'update_time'             => 'datetime', //更新时间
        'clock_time'             => 'datetime', //打卡时间
        'check_work_day'             => 'date', //考勤日期
        'late_leave_early_type'             => 'tinyint', //[select] 【1-早退|2-迟到】
        'reserve_time'             => 'datetime', //设定打卡时间
    ];

    //处理数据模型 
    public static function fillModels($models){ 
        $list = []; 
        foreach ($models as $model) { 
            $listItem = static::fillModel($model); 
            $list[] = $listItem; 
        } 
        return $list; 
    } 

    public static function fillModel($model){ 
        $data = [];
        $data['id'] = $model['id'];
        $data['uid'] = $model['uid'];
        $data['remark'] = $model['remark'];
        $data['create_time'] = $model['create_time'];
        $data['examine_admin_name'] = $model['examine_admin_name'];
        $data['admin_name'] = $model['admin_name'];
        $data['status'] = (string)$model['status'];
        $data['update_time'] = $model['update_time'];
        $data['clock_time'] = $model['clock_time'];
        $data['check_work_day'] = $model['check_work_day'];
        $data['late_leave_early_type'] = (string)$model['late_leave_early_type'];
        $data['late_leave_early_type_name'] = self::getLateLeaveEarlyTypeName($model['late_leave_early_type']);
        $data['reserve_time'] = $model['reserve_time'];
        return $data;
    } 

    /** 
     *【方法注释】处理[select] 【1-早退|2-迟到】
     *@param $value 传入的值
     *@param string 返回的值
     */
    public static function getLateLeaveEarlyTypeName($value){
        $arr = [
            1=>"早退",
            2=>"迟到",
        ];
        return $arr[$value];
    } 

    /** 
     *【方法注释】获取数据列表 
     *@param $where 查询的条件数组
     *@param $limit_start 获取数据，从第$limit_start条数据开始
     *@param $page_size 获取数据，从第$limit_start条数据开始，取$page_size条数据
     *@param array 返回的数据，数组
     */
    public static function getList($where, $limit_start, $page_size){
        $lists =  self::where($where)->order('id','desc')->limit($limit_start,$page_size)->select();
        return self::fillModels($lists);
    } 

    /** 
     *【方法注释】获取数据条数 
     *@param $where 查询的条件数组
     *@param int 返回的数据条数
     */
    public static function getCount($where){
        return self::where($where)->count();
    } 

    /** 
     *【方法注释】获取单条数据 
     *@param $where 查询的条件数组
     *@param array 返回的单条数据
     */
    public static function getOne($where){
        return self::fillModel(self::where($where)->find());
    } 

} 
